Canonicalize volatile system prompt headers in OpenAI paths#528
Open
Thump604 wants to merge 1 commit into
Open
Canonicalize volatile system prompt headers in OpenAI paths#528Thump604 wants to merge 1 commit into
Thump604 wants to merge 1 commit into
Conversation
janhilgard
approved these changes
May 16, 2026
Collaborator
janhilgard
left a comment
There was a problem hiding this comment.
Clean implementation. The prompt_canonicalize.py module is well-isolated with an extensible _STRIPPERS tuple, and canonicalize_system_messages() correctly avoids mutation (copies only changed messages, returns the original list when nothing changes).
Review
- Regex
(?im)^x-anthropic-billing-header:[^\n]*(?:\n|$)— multiline + case-insensitive + anchored. Correctly strips the full line including trailing newline. - Only targets
systemrole — user content is preserved (explicitly verified by the chat completion test). Nonepassthrough is correct.- Placement in
server.pyis right: after_normalize_messages()but before media extraction. - Tests cover the unit helper (strip, idempotent, None/empty), Chat Completions path, and Responses path.
Minor note
The Anthropic adapter in anthropic_adapter.py has its own inline regex (re.sub(r"x-anthropic-billing-header:[^\n]*\n?", "", system_text)) without (?im) flags or ^ anchor. Not blocking, but a future cleanup could have the adapter call canonicalize_system_prompt() instead of duplicating the pattern.
CI 9/9. LGTM.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs #524.
Summary
x-anthropic-billing-headerstripper.Local repro / observed behavior
On current
waybarrios/vllm-mlxmain (f068991when this branch was cut), the Anthropic Messages adapter removesx-anthropic-billing-header:fromrequest.systeminvllm_mlx/api/anthropic_adapter.py::anthropic_to_openai, but the OpenAI server paths did not apply the same canonicalization:vllm_mlx/server.py::_prepare_chat_messagesvllm_mlx/server.py::_prepare_responses_requestA Chat Completions system message or Responses
instructionsvalue containing:was still present in the prepared system message sent to the engine.
Expected behavior
The validated billing-header line is non-semantic request metadata and should be removed from system-role text before engine execution. User-role content with the same text is preserved, and user-visible timestamp text is not stripped.
Minimal patch shape
vllm_mlx/api/prompt_canonicalize.pymodule with a static stripper list andcanonicalize_system_prompt().canonicalize_system_messages()helper that copies only changed system messages.Explicitly not claimed
Verification